(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            orderInfo: {
                orders: [],
                total: 0,
                records: 1,
                moreCondition: false,
                totalMount: 0.00,
                totalNum: 0,
                conditions: {
                }
            },
            logistic: {
                logisticOrgCode: '',
                logisticOrgName: '',
                remark: '',
                logisticNum: ''
            },
            orderId:'',
            context:'',
            appraiseScore:'5'
        },
        _initMethod: function () {
            vc.component._listOrders(DEFAULT_PAGE, DEFAULT_ROWS);
            $(".problem-lside a.nli").each(function () {
                $(this).click(function () {
                    $(this).next("ul.ulson").slideToggle(200);
                    $(this).children("b").toggleClass("arrow");
                })
            });
        },
        _initEvent: function () {
            vc.on('pagination', 'page_event', function (_currentPage) {
                vc.component._listOrders(_currentPage, DEFAULT_ROWS);
            });
        },
        methods: {
            _saveConfirmOrder:function(){
                if(vc.component.orderId == ''){
                    vc.toast("订单编号出错");
                    return;
                }
                vc.http.apiPost(
                    '/storeOrder/receiveStoreOrderCart',
                    JSON.stringify({
                        orderId:vc.component.orderId,
                        personId:vc.component.personId,
                        cartId:vc.component.cartId,
                        shopId:vc.component.shopId
                    }), {
                        emulateJSON: true
                    },
                    function(json, res) {
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            vc.toast("已确认收货");
                            vc.component._listOrders(DEFAULT_PAGE, DEFAULT_ROWS);
                            vc.component.closeTips();
                            return;
                        }else{
                            vc.toast(_json.data);
                        }
                    },
                    function(errInfo, error) {
                        console.log('请求失败处理');
                        vc.toast(errInfo);
                    });
            },
            _saveEvaluate:function(){
                if(vc.component.orderId == ''){
                    vc.toast("订单编号出错");
                    return;
                }
                if(vc.component.context == ''){
                    vc.toast("请填写评价内容");
                    return;
                }
                vc.http.apiPost(
                    '/shopAppraise/saveShopAppraise',
                    JSON.stringify({
                        parentAppraiseId:'-1',
                        orderId:vc.component.orderId,
                        context:vc.component.context,
                        shopId:vc.component.shopId,
                        appraiseUserId:vc.component.appraiseUserId,
                        appraiseUserName:vc.component.appraiseUserName,
                        appraiseScore:vc.component.appraiseScore,
                        objId:vc.component.objId,
                        objType:vc.component.objType,
                        cartId:vc.component.cartId,
                    }), {
                        emulateJSON: true
                    },
                    function(json, res) {
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            vc.toast("成功");
                            vc.component._listOrders(DEFAULT_PAGE, DEFAULT_ROWS);
                            vc.component.closeTips();
                            return;
                        }else{
                            vc.toast(_json.data);
                        }
                    },
                    function(errInfo, error) {
                        console.log('请求失败处理');
                        vc.toast(errInfo);
                    });
            },
            _expeditingDelivery: function(_order) {
                var param = {
                     orderId: _order.orderId,
                     cartId: _order.cartId,
                     personId: _order.personId,
                     eventMsg: '用户催发货',
                     shopId: _order.shopId
                };
                vc.http.apiPost(
                    '/storeOrder/expeditingDelivery',
                    JSON.stringify(param), {
                        emulateJSON: true
                    },
                    function (json, res) {
                        vc.message("已催商家发货");
                    },
                    function (errInfo, error) {
                        vc.message(json);
                    });
            },
            //物流信息弹窗
            _logisticOrder: function (_order) {
                $("#mask").css("height", $(document).height()).show();
                $("#mask").css("margin-top", '-200px');
                $("#mask").css("z-index", '1200');
                $("#logistic").show();
                var param = {
                    params: {page:1,row:1,orderId:_order.orderId,shopId:_order.shopId}
                };
                //发送get请求
                vc.http.apiGet('storeOrder.queryLogisticsDetail',
                    param,
                    function (json, res) {
                        var _logistic = JSON.parse(json);
                        vc.component.logistic = _logistic.data[0];
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            //确认收货弹窗
            _confirmOrder: function (_order) {
                $("#mask").css("height", $(document).height()).show();
                $("#mask").css("margin-top", '-200px');
                $("#mask").css("z-index", '1200');
                $("#confirm").show();
                vc.component.orderId = _order.orderId;
                vc.component.personId = _order.personId;
                vc.component.cartId = _order.cartId;
                vc.component.shopId = _order.shopId;
            },
             closeTips:function(){
                $("#mask").hide();
                $("#confirm").hide();
                $("#evaluate").hide();
                $("#logistic").hide();
                $("#return").hide();
            },
            _evaluateOrder: function (_order) {
                $("#mask").css("height", $(document).height()).show();
                $("#mask").css("margin-top", '-200px');
                $("#mask").css("z-index", '1200');
                $("#evaluate").show();
                vc.component.orderId = _order.orderId;
                vc.component.shopId = _order.shopId;
                vc.component.appraiseUserId = _order.personId;
                vc.component.appraiseUserName = _order.personName;
                vc.component.objId = _order.productId;
                vc.component.objType = "1001";
                vc.component.cartId = _order.cartId;
            },
            _payOrder: function (_order) {
                vc.jumpToPage("/pageLR.html#/pages/plateform/pay?orderId=" + _order.orderId);
            },
            _closeOrder : function (_order) {
                if(_order.orderId == ''){
                    vc.toast("订单编号出错");
                    return;
                }
                vc.http.apiPost(
                    'storeOrder.closeStoreOrder',
                    JSON.stringify(_order), {
                        emulateJSON: true
                    },
                    function (json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            vc.component._listOrders(DEFAULT_PAGE, DEFAULT_ROWS);
                            return;
                        }
                        vc.message(_json.msg);
                    },
                    function (errInfo, error) {
                        vc.message(json);
                    });
            },
            //获取用户订单
            _listOrders: function (_page, _rows) {
                var param = {
                    params: {page:_page, row:_rows,states:'2002,2012,2013,3003,4004,5005,6006,7007,8008,9009,2102,3103,3104,3004'}
                };
                //发送get请求
                vc.http.apiGet('storeOrder.queryUserStoreOrderCart',
                    param,
                    function (json, res) {
                        var _orderInfo = JSON.parse(json);
                        vc.component.orderInfo.orders = _orderInfo.data;
                        vc.component.orderInfo.total = _orderInfo.total;
                        vc.component.orderInfo.records = _orderInfo.records;
                        vc.emit('pagination', 'init', {
                            total: vc.component.orderInfo.records,
                            currentPage: _page,
                            totalItem: _orderInfo.total
                        });
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _toReturn: function (_order) {
                $("#mask").css("height", $(document).height()).show();
                $("#mask").css("margin-top", '-200px');
                $("#mask").css("z-index", '1200');
                $("#return").show();
                vc.component.orderId = _order.orderId;
                vc.component.personId = _order.personId;
                vc.component.cartId = _order.cartId;
                vc.component.shopId = _order.shopId;
            },
            _saveReturn:function(){
                if(vc.component.orderId == ''){
                    vc.toast("订单编号出错");
                    return;
                }
                if(this.context == ''){
                    uni.showToast({
                        title:'请填写退货原因',
                        icon:'none'
                    });
                    return ;
                }
                vc.http.apiPost(
                    '/storeOrderCartReturn.saveStoreOrderCartReturn',
                    JSON.stringify({
                        orderId:vc.component.orderId,
                        returnReason:vc.component.context,
                        shopId:vc.component.shopId,
                        personId:vc.component.personId,
                        orderId:vc.component.orderId,
                        cartId:vc.component.cartId
                    }), {
                        emulateJSON: true
                    },
                    function(json, res) {
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            vc.toast("退货成功");
                            vc.component._listOrders(DEFAULT_PAGE, DEFAULT_ROWS);
                            vc.component.closeTips();
                            return;
                        }else{
                            vc.toast(_json.data);
                        }

                    },
                    function(errInfo, error) {
                        console.log('请求失败处理');
                        vc.toast(errInfo);
                    });
            },
        }
    });

})(window.vc);
